const recast = require('recast');
const fs = require('fs');
const path = require('path');
const OUT_DIR = 'output';

// 读取原始代码
const code = fs.readFileSync(path.resolve(__dirname, 'code.js'), 'utf-8');

// 使用recast解析代码为AST
const ast = recast.parse(code);

// 使用recast将AST转换回代码
const output = recast.print(ast).code;

// 将转换后的代码写入文件
fs.writeFileSync(path.resolve(OUT_DIR, 'recastSame.js'), output, 'utf-8');

// 比较原始代码和转换后的代码
if (code === output) {
    console.log('The transformed code is identical to the original code.');
} else {
    console.log('There are differences between the original and transformed code.');
}